package top.xiaoshuaila.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.xiaoshuaila.pojo.Employee;
import top.xiaoshuaila.pojo.RespBean;
import top.xiaoshuaila.pojo.RespPageBean;
import top.xiaoshuaila.pojo.Salary;
import top.xiaoshuaila.service.IEmployeeService;
import top.xiaoshuaila.service.ISalaryService;

import java.util.List;

@RestController
@RequestMapping("/salary/sobcfg")
@Api(tags = "工资账套管理接口")
public class SalaySobCfgController {

    @Autowired
    private ISalaryService salaryService;

    @Autowired
    private IEmployeeService employeeService;



    @ApiOperation("获取所有工资账套")
    @GetMapping("/salaries")
    public List<Salary>getAllSalaries(){
        return salaryService.list();
    }

    @ApiOperation("获取所有员工账套")
    @GetMapping("/")
    public RespPageBean getEmployeeWithSalary(
            @RequestParam(defaultValue = "1") Integer currenttPage,
            @RequestParam(defaultValue = "10") Integer size){
        return employeeService.getEmployeeWithSalary(currenttPage,
                size);
    }
    @ApiOperation("更新员工账套")
    @PutMapping("/")
    public RespBean updateEmployeeSalary(Integer eid, Integer sid){
        if(employeeService.update(new UpdateWrapper<Employee>()
                .set("sid",sid)
                .eq("id",eid)))
            return RespBean.success("更新成功!");
        else return RespBean.error("更新失败!");
    }
}
